'''
Mars data storage utilities.
'''
from __future__ import unicode_literals
try:
    import cPickle as pickle
except ImportError:
    import pickle
import os

STORE_LOCATION = '/home/godjonez/TCJ'

SUPPORTED_DATA = {
    'spectrometer_calibration': 'spectro',
    'wheels_calibration': 'wheels',
}

def get_data(dataname):
    '''
    Load data and return it.
    '''
    print "Attempting to get "+dataname
    filename = SUPPORTED_DATA[dataname]
    try:
        with open(os.path.join(STORE_LOCATION, filename), 'rb') as fh:
            data = pickle.load(fh)
    except (IOError, EOFError):
        data = ''
    print "Got "+repr(data)
    return data

def save_data(dataname, data):
    '''
    Save data.
    '''
    filename = SUPPORTED_DATA[dataname]
    with open(os.path.join(STORE_LOCATION, filename), 'wb') as fh:
        pickle.dump(data, fh)

